var app = getApp();

Page({
    data: {
        navH: app.globalData.navHeight,
        msgList: [ {
            name: "我是**",
            msg: "正在去买"
        }, {
            name: "我是**",
            msg: "喜欢了这件商品"
        }, {
            name: "小**",
            msg: "正在去买"
        }, {
            name: "小**",
            msg: "正在去买"
        }, {
            name: "小**",
            msg: "正在去买"
        }, {
            name: "我是**",
            msg: "喜欢了这件商品"
        }, {
            name: "我是**",
            msg: "喜欢了这件商品"
        }, {
            name: "我是**",
            msg: "喜欢了这件商品"
        }, {
            name: "小**",
            msg: "正在去买"
        }, {
            name: "小**",
            msg: "正在去买"
        }, {
            name: "小**",
            msg: "正在去买"
        }, {
            name: "小**",
            msg: "正在去买"
        }, {
            name: "小**",
            msg: "正在去买"
        }, {
            name: "我是**",
            msg: "正在去买"
        }, {
            name: "我是**",
            msg: "正在去买"
        }, {
            name: "我是**",
            msg: "喜欢了这件商品"
        }, {
            name: "我是**",
            msg: "喜欢了这件商品"
        }, {
            name: "我是**",
            msg: "喜欢了这件商品"
        }, {
            name: "我是**",
            msg: "正在去买"
        }, {
            name: "小**",
            msg: "喜欢了这件商品"
        }, {
            name: "小**",
            msg: "正在去买"
        } ],
        current: 0,
        pvd: null,
        duration: 500,
        id: "",
        toView: null,
        page: 1,
        vListAll: [],
        appletKeyword: "",
        video_title: ""
    },
    navBack: function() {
        wx.navigateBack();
    },
    toGoodsPage: function(a) {
        app.globalData.userInfo ? (a = a.currentTarget.dataset.goods_id, wx.navigateTo({
            url: "../goods/goods?source=6&goods_id=" + a
        })) : app.checkLogin();
    },
    dianZan: function(a) {
        app.globalData.userInfo ? (a = a.currentTarget.dataset.vdx, this.data.vListAll[a].zan || (this.data.vListAll[a].zan = !0, 
        this.data.vListAll[a].videoLikeCount = parseInt(this.data.vListAll[a].videoLikeCount) + 1, 
        this.setData({
            vListAll: this.data.vListAll
        }))) : app.checkLogin();
    },
    copyGuideArt: function(a) {
        app.globalData.userInfo ? (a = a.currentTarget.dataset.art, wx.setClipboardData({
            data: a,
            success: function(a) {
                app.globalData.showSmart = !1;
            }
        })) : app.checkLogin();
    },
    loginAfter: function(a) {
        app.loginAfter(a);
    },
    loginCancel: function() {
        app.loginCancel();
    },
    onChange: function(a) {
        var t = this;
        console.log(a.detail.current);
        var e, o, n, a = a.detail.current;
        t.setData({
            current: a
        }), wx.createVideoContext(t.data.pvd, this).pause(), 0 == t.data.current ? (a = "pvd" + this.data.vListAll[t.data.current].goods_id, 
        console.log("第一页原生video自动播放", a), t.setData({
            pvd: a
        }), (e = wx.createVideoContext(t.data.pvd, this)).seek(0), setTimeout(function() {
            e.play();
        }, 500)) : (n = "pvd" + this.data.vListAll[t.data.current].goods_id, console.log("原生video自动播放", n), 
        t.setData({
            pvd: n
        }), (o = wx.createVideoContext(t.data.pvd, this)).seek(0), setTimeout(function() {
            o.play();
        }, 500)), t.data.vListAll.length - this.data.current <= 3 && (n = t.data.page + 1, 
        t.setData({
            page: n
        }), t.getVideoList("more"));
    },
    onLoad: function(a) {
        var t = this;
        void 0 === a.id && wx.navigateBack(), app.util.request({
            url: "entry/wxapp/Setting",
            data: {
                name: "appletKeyword"
            },
            showLoading: !1,
            success: function(a) {
                a = a.data.data, t.setData({
                    appletKeyword: a
                });
            }
        });
        var e = (n = getCurrentPages())[n.length - 2].data.categoryData[a.id].listData[a.idx], o = "pvd" + e.goods_id, n = [ e ];
        this.setData({
            id: e.goods_id,
            cid: a.cid,
            cur: a.id,
            pvd: o,
            vListAll: n,
            toView: "msg-" + (t.data.msgList.length - 1)
        }), t.getVideoList("refresh");
    },
    getCurrentData: function() {
        return console.log("获取当前页面数据", this.data.vListAll), this.data.vListAll;
    },
    getVideoList: function(o) {
        var n = this, s = n.getCurrentData();
        console.log("获取当前的数据", s), n.data.v_loading || (n.data.v_loading = !0, app.util.request({
            url: "entry/wxapp/getTbVideos",
            showLoading: !1,
            data: {
                page: n.data.page,
                cid: n.data.cid
            },
            success: function(a) {
                var t, e;
                a.data.data.length < 1 || (console.log("通过cid获取到的视频数据", a), t = a.data.data, s = "refresh" === o ? n.data.vListAll.concat(t) : s === t ? "" : s.concat(a.data.data), 
                console.log("vListAll里的视频数据", s), e = [], a = (a = s).reduce(function(a, t) {
                    return e[t.goods_id] || (e[t.goods_id] = a.push(t)), a;
                }, []), console.log("去重", a), n.setData({
                    vListAll: a
                }));
            },
            complete: function() {
                n.data.v_loading = !1;
            }
        }));
    },
    onReady: function() {},
    onShow: function() {
        app.reUserInfo();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function(a) {
        var t = "button" == a.from ? a.target.dataset.vdx : 0, a = this.data.vListAll[t].video_title, t = this.data.vListAll[t].videoCoverImg;
        return {
            title: a,
            path: "/first_duoduoke/pages/shake-coupon/shake-coupon" + (void 0 !== app.globalData.userInfo.uid ? "?from_uid=" + app.globalData.userInfo.uid + "?from_act=share" : "&from_act=share"),
            imageUrl: t,
            success: function(a) {
                "shareAppMessage:ok" == a.errMsg ? wx.showToast({
                    title: "分享成功",
                    icon: "success"
                }) : wx.showToast({
                    title: "分享失败",
                    icon: "none"
                });
            },
            fail: function(a) {
                "shareAppMessage:fail cancel" == a.errMsg || a.errMsg, wx.showToast({
                    title: "分享失败",
                    icon: "none"
                });
            }
        };
    }
});